﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JamesThew.Dashboard
{
    public partial class PostManager : System.Web.UI.Page
    {
        public String TableData;
        public List<Post> lp;
        public PostDB pdb;
        public PostsCategoriesDB pcdb;
        public UserDB udb;
        public String ListCategory;
        public String PostType;


        protected void Page_Load(object sender, EventArgs e)
        {
            this.pdb = new PostDB();
            this.pcdb = new PostsCategoriesDB();
            this.udb = new UserDB();

            /* Assign Posttype */
            String PostType = Request.QueryString["type"];
            if (PostType == null || PostType == "") PostType = "recipe";
            this.PostType = PostType;

            String[] Args = new string[] { null, null, null, null, null, null, null, null, null, PostType, null, null };

            this.lp = this.pdb.Get(Args);
            this.TableData = this.GenerateTableData(this.lp);
        }

        public String GenerateTableData(List<Post> posts) {
            
            String output = "";

            foreach (Post p in posts) {

                output += "<tr><td><input type=\"checkbox\" name=\"" + p.PostID + "\" /></td>";
                output += "<td><strong><a href=\"Posts.aspx?type="+p.PostType+"&action=edit&id=" + p.PostID + "\">" + p.PostTitle + "</a></strong></td>";
                output += "<td>" + this.udb.GetUserName(p.PostAuthor) + "</td>";
                output += "<td>" + this.pcdb.GetListCatOfPost(p.PostID, "text") + "</td>";
                output += "<td>" + p.PostModified + "<br /><em>" + p.PostStatus + "</em></td>";
                output += "</tr>";
            
            }
            return output;
        }
    }
}